public class Solution1 {
    public ListNode detectCycle(ListNode head) {
        if(head==null){
            return null;

        }
        ListNode fast=head;
        ListNode slow=head;
        while(fast!=null&&fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
        
         if(fast==slow){//找到了相遇点
            break;
        }

        }
        
        if(fast==null||fast.next==null){
            return null;//没环
        }
        
       
        slow=head;//slow和fast到环的入口点距离相等，所以当它俩相等时就找到了入口点
        while(fast!=slow){
            fast=fast.next;
            slow=slow.next;
        }
        return fast;
    }
}